package net.sx.minemodule.mvp.item;

import com.kedll.library.adapter.MultiSelectAdapter;
import com.kedll.library.adapter.MultiTypeAdapter;
import com.kedll.library.mvp.BaseItem;

import net.sx.minemodule.R;
import net.sx.minemodule.mvp.bean.RefundArryBean;

public class RefundArrayItem extends BaseItem<RefundArryBean> {
    private MultiTypeAdapter adapter;
    public RefundArrayItem(RefundArryBean data,MultiTypeAdapter adapter) {
        super(data);
        this.adapter = adapter;
        setOnClickListener(v -> {
            getMultiSelectAdapter().toggle(data);
            setSelected(!data.isSelected());
            adapter.notifyItemRangeChanged(0, adapter.getItemCount());
            if (adapter.getOnItemClickListener() != null) {
                adapter.getOnItemClickListener().onItemClicked(v,this);
            }
        });
    }

    @Override
    public int getLayout() {
        return R.layout.mine_item_refundarray;
    }
    public String getTitle(){
        return getData().getTitle();
    }
    private MultiSelectAdapter<RefundArryBean> getMultiSelectAdapter() {
        return (MultiSelectAdapter<RefundArryBean>) adapter;
    }

    public boolean isSelected() {
        return getData().isSelected();
    }

    private void setSelected(boolean selected) {
        for (MultiTypeAdapter.IItem item : getMultiSelectAdapter().getValues()) {
            ((RefundArrayItem)item).getData().setSelected(false);
        }
        getData().setSelected(selected);

    }

}
